<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="jt" uri="http://www.jsoft.org/tags/jsoft"%>
<%@ taglib prefix="jh" uri="http://www.jsoft.org/tags/jsoft-html"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	if(path!=null&&path.equals("/")){
	   path="";
	} 
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>数据字典管理</title>
		<link href="<%=basePath%>admin/styles/default.css" rel="stylesheet"
			type="text/css" />
		<link href="<%=basePath%>admin/styles/page.css" rel="stylesheet"
			type="text/css" />
		<script type="text/javascript">
		function form_delete(href)
		{
			if(confirm("您确定要删除吗？执行删除后数据将无法恢复！"))
			{
   				window.location.href = href;
   			}			
		}
		</script>
		<script type="text/javascript">
        function frameHeight() {
        	var height = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
			return height;
        }
        
        window.onload = function(){frameHeightSet();}
		window.onresize = function(){frameHeightSet();}
		
		function frameHeightSet() {
			var height = frameHeight();
        	if (height<=300) {
        		height = 300;
        	}
        	document.getElementById("dicList").style.height = height-210+"px";
        	document.getElementById("dicValue").style.height = height-210+"px";
		}
		</script>
		<script type="text/javascript" src="<%=basePath%>admin/scripts/jquery.js"></script>
		<script type="text/javascript">
		window.onload = function(){
			loadDic();
			frameHeightSet();
		}
		function loadDic(){
			var httpPath = "<%=basePath%>dic/ajax/allDic.html?random="+Math.random();
			$.get(httpPath, null, showHttpDic);
		}
		function showHttpDic(data){
			var dicOption = "";
			dicOption += "<option value=\"0\">";
			dicOption += "-请选择-";
			dicOption += "</option>";
			try{
				data = data.replace(/(\r\n|\n)/ig,'');
				var dicj = eval("(" + data + ")");
				len = dicj.dics.length;
				for (i = 0; i < len; i++) {
					itemId = dicj.dics[i].id;
					itemName = dicj.dics[i].name;
					dicOption += "<option value=\""+itemId+"\">";
					dicOption += itemName+"("+itemId+")";
					dicOption += "</option>";
				}
			}catch(e){
				alert(e);
			}
			$("#dic").html(dicOption);
		}
		function changeDic(obj){
			var httpPath = "<%=basePath%>dic/ajax/dic-value.html?id="+obj.value+"&random="+Math.random();
			$.get(httpPath, null, showHttpValue);
		}
		function showHttpValue(data){
			var valueOption = "";
			valueOption += "<option value=\"0\">";
			valueOption += "-请选择-";
			valueOption += "</option>";
			try{
				data = data.replace(/(\r\n|\n)/ig,'');
				var valuej = eval("(" + data + ")");
				len = valuej.values.length;
				for (i = 0; i < len; i++) {
					itemId = valuej.values[i].id;
					itemName = valuej.values[i].name;
					valueOption += "<option value=\""+itemId+"\">";
					valueOption += itemName+"("+itemId+")";
					valueOption += "</option>";
				}
			}catch(e){
				alert(e);
			}
			$("#dic_value").html(valueOption);
		}
		</script>
	</head>

	<body>
		<div class="title">
			<h2>
				数据字典管理
			</h2>
		</div>
		<div id="container">
			<!-- table -->
			<div style="padding-bottom: 3px;">
				字典数据预览：
				<select id="dic" name="dic" onchange="changeDic(this);">
					<option value="0">-请选择-</option>
				</select>
				<select id="dic_value" name="dic_value">
					<option value="0">-请选择-</option>
				</select>
				<a href="<%=basePath%>admin/system/dic/updateDic.html">更新字典缓存</a>
				<font color="red">${requestScope.updateMsg}</font>
			</div>
			<table width="100%" cellpadding="3" cellspacing="3" border="0" bgcolor="#ebeff1">
				<tr bgcolor="#FFFFFF">
					<td width="50%">
						<!-- diclist -->
						<div id="dicList" style="overflow: auto; height: 480px;">
						<table class="table01">
							<tr>
								<th width="100">编号</th>
								<th>名称</th>
								<th>状态</th>
								<th width="60">操作</th>
							</tr>
							<c:forEach items="${requestScope.diclist}" var="dic">
							<tr <c:if test="${requestScope.editDiclist.id eq dic.id}">class="selected"</c:if>>
								<td>
									<a href="<%=basePath%>admin/system/dic/value-list.html?dicId=${dic.id}">
										<c:out value="${dic.id}"/>
									</a>
								</td>
								<td>
									<a href="<%=basePath%>admin/system/dic/value-list.html?dicId=${dic.id}">
										<c:out value="${dic.name}"/>
									</a>
								</td>
								<td>
									<c:if test="${dic.state eq 1}"><font color="blue">启用</font></c:if>
									<c:if test="${dic.state eq 0}"><font color="red">停用</font></c:if>
									(<c:out value="${dic.state}"/>)
								</td>
								<td>
									<a href="<%=basePath%>admin/system/dic/dic-edit.html?id=${dic.id}">修改</a>
									<a href="javascript:form_delete('<%=basePath%>admin/system/dic/dic-delete.html?id=${dic.id}');">删除</a>
								</td>
							</tr>
							</c:forEach>
						</table>
						</div>
					</td>
					<td width="50%">
						<!-- dicvalue -->
						<div id="dicValue" style="overflow: auto; height: 480px;">
						<table class="table01">
							<tr>
								<th width="50">编号</th>
								<th>字典</th>
								<th>名称</th>
								<th>状态</th>
								<th width="60">操作</th>
							</tr>
							<c:forEach items="${requestScope.dicvalue}" var="value">
							<tr <c:if test="${requestScope.editDicvalue.id eq value.id}">class="selected"</c:if>>
								<td><c:out value="${value.id}"/></td>
								<td><c:out value="${value.dicId}"/></td>
								<td><c:out value="${value.name}"/></td>
								<td>
									<c:if test="${value.state eq 1}"><font color="blue">启用</font></c:if>
									<c:if test="${value.state eq 0}"><font color="red">停用</font></c:if>
									(<c:out value="${value.state}"/>)
								</td>
								<td>
									<a href="<%=basePath%>admin/system/dic/value-edit.html?id=${value.id}">修改</a>
									<a href="javascript:form_delete('<%=basePath%>admin/system/dic/value-delete.html?id=${value.id}&dicId=${value.dicId}');">删除</a>
								</td>
							</tr>
							</c:forEach>
						</table>
						</div>
					</td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td>
						<!-- diclist-edit -->
						<form action="<%=basePath%>admin/system/dic/dic-save.html" method="post">
						<input type="submit" value="保存" class="button">
						<input type="reset" value="重置" class="button">
						<font color="red">${requestScope.dicSaveMsg}</font>
						<table width="100%" cellpadding="2" cellspacing="1" border="0" bgcolor="#e3e3e3">
							<tr>
								<td width="15%" nowrap="nowrap" bgcolor="#f7fbff">
									编号：
								</td>
								<td width="35%" bgcolor="#FFFFFF">
									<input type="text" name="id" class="text" value="${requestScope.editDiclist.id}">
								</td>
								<td width="15%" nowrap="nowrap" bgcolor="#f7fbff">
									状态：
								</td>
								<td width="35%" bgcolor="#FFFFFF">
									<select name="state" id="state">
										<option value="1" <c:if test="${requestScope.editDiclist.state eq 1}">selected="selected"</c:if>>- 启用 -</option>
										<option value="0" <c:if test="${requestScope.editDiclist.state eq 0}">selected="selected"</c:if>>- 停用 -</option>
									</select>
								</td>
							</tr>
							<tr>
								<td width="15%" nowrap="nowrap" bgcolor="#f7fbff">
									中文名：
								</td>
								<td width="35%" bgcolor="#FFFFFF">
									<input type="text" name="name" class="text" value="${requestScope.editDiclist.name}">
								</td>
								<td width="15%" nowrap="nowrap" bgcolor="#f7fbff">
									中文描述：
								</td>
								<td width="35%" bgcolor="#FFFFFF">
									<input type="text" name="des" class="text" value="${requestScope.editDiclist.des}">
								</td>
							</tr>
							<tr>
								<td width="15%" nowrap="nowrap" bgcolor="#f7fbff">
									英文名：
								</td>
								<td width="35%" bgcolor="#FFFFFF">
									<input type="text" name="nameEn" class="text" value="${requestScope.editDiclist.nameEn}">
								</td>
								<td width="15%" nowrap="nowrap" bgcolor="#f7fbff">
									英文描述：
								</td>
								<td width="35%" bgcolor="#FFFFFF">
									<input type="text" name="desEn" class="text" value="${requestScope.editDiclist.desEn}">
								</td>
							</tr>
						</table>
						</form>
					</td>
					<td>
						<!-- dicvalue-edit -->
						<form action="<%=basePath%>admin/system/dic/value-save.html" method="post">
						<input type="submit" value="保存" class="button">
						<input type="reset" value="重置" class="button">
						<input type="button" value="添加" class="button" onclick="window.location.href='<%=basePath%>admin/system/dic/value-list.html?dicId=${requestScope.editDiclist.id}';">
						<font color="red">${requestScope.valueSaveMsg}</font>
						<table width="100%" cellpadding="2" cellspacing="1" border="0" bgcolor="#e3e3e3">
							<tr>
								<td width="15%" nowrap="nowrap" bgcolor="#f7fbff">
									编号/字典：
								</td>
								<td width="35%" bgcolor="#FFFFFF">
									<input type="hidden" name="id" class="text" value="${requestScope.editDicvalue.id}">
									<font color="red" id="id_txt">${requestScope.editDicvalue.id eq null?"无编号":requestScope.editDicvalue.id}</font>
									/
									<select name="dicId" style="width: 110px;">
										<option value="0">-请选择-</option>
										<c:forEach items="${requestScope.diclist}" var="dic">
										<option value="${dic.id}" <c:if test="${editDiclist.id eq dic.id}">selected="selected"</c:if>>${dic.name}(${dic.id})</option>
										</c:forEach>
									</select>
								</td>
								<td width="15%" nowrap="nowrap" bgcolor="#f7fbff">
									状态：
								</td>
								<td width="35%" bgcolor="#FFFFFF">
									<select name="state" id="state">
										<option value="1" <c:if test="${requestScope.editDicvalue.state eq 1}">selected="selected"</c:if>>- 启用 -</option>
										<option value="0" <c:if test="${requestScope.editDicvalue.state eq 0}">selected="selected"</c:if>>- 停用 -</option>
									</select>
								</td>
							</tr>
							<tr>
								<td width="15%" nowrap="nowrap" bgcolor="#f7fbff">
									中文名：
								</td>
								<td width="35%" bgcolor="#FFFFFF">
									<input type="text" name="name" class="text" value="${requestScope.editDicvalue.name}">
								</td>
								<td width="15%" nowrap="nowrap" bgcolor="#f7fbff">
									中文描述：
								</td>
								<td width="35%" bgcolor="#FFFFFF">
									<input type="text" name="des" class="text" value="${requestScope.editDicvalue.des}">
								</td>
							</tr>
							<tr>
								<td width="15%" nowrap="nowrap" bgcolor="#f7fbff">
									英文名：
								</td>
								<td width="35%" bgcolor="#FFFFFF">
									<input type="text" name="nameEn" class="text" value="${requestScope.editDicvalue.nameEn}">
								</td>
								<td width="15%" nowrap="nowrap" bgcolor="#f7fbff">
									英文描述：
								</td>
								<td width="35%" bgcolor="#FFFFFF">
									<input type="text" name="desEn" class="text" value="${requestScope.editDicvalue.desEn}">
								</td>
							</tr>
						</table>
						</form>
					</td>
				</tr>
			</table>
		</div>
	</body>
</html>
